//
//  UUNotificationCell.m
//  UUCharterSupplier
//
//  Created by ZhangAo on 06/03/2018.
//  Copyright © 2018 UUCharter. All rights reserved.
//

#import "UUNotificationCell.h"

@interface UUNotificationCell ()

@property (nonatomic, strong) UIView *containerView;
@property (nonatomic, strong) UIView *containerContentView;

@property (nonatomic, strong) UILabel *timeLabel;

@end

@implementation UUNotificationCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor clearColor];
        self.contentView.backgroundColor = [UIColor clearColor];
        
        self.containerView = [UIView new];
        self.containerView.layer.cornerRadius = 4;
        [self.contentView addSubview:self.containerView];
        [self.containerView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.mas_equalTo(10);
            make.right.bottom.mas_equalTo(-10);
        }];
        
        self.containerContentView = [UIView new];
        [self.containerView addSubview:self.containerContentView];
        [self.containerContentView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(0);
            make.left.mas_equalTo(10);
            make.right.mas_equalTo(-10);
        }];
        
        self.timeLabel = [UILabel new];
        self.timeLabel.textColor = COMMON_TEXT_LIGHT_COLOR;
        self.timeLabel.font = [UIFont systemFontOfSize:12];
        [self.containerView addSubview:self.timeLabel];
        [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.containerContentView.mas_bottom).offset(15);
            make.left.width.equalTo(self.containerContentView);
            make.height.mas_equalTo(17);
            make.bottom.mas_equalTo(-15);
        }];
    }
    return self;
}

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
    [super setHighlighted:highlighted animated:animated];
    
    if (highlighted) {
        self.containerView.backgroundColor = COMMON_CELL_SELECTED_COLOR;
    } else {
        self.containerView.backgroundColor = [UIColor whiteColor];
    }
}

- (void)setupWithModel:(UUNotificationModel *)model {
    self.timeLabel.text = [model.createTime formatDateByFormatString:@"MM月dd日 HH:mm"];
}

@end
